package net.pimpas.operation.operation.group;

import java.util.ArrayList;
import java.util.List;

import net.pimpas.operation.operation.Operation;

public abstract class OperationGroupAbstract implements OperationGroup<List<Object>> {

	private List<Operation> operations;
	
	public OperationGroupAbstract() {
		this.setOperations(new ArrayList<Operation>());
	}
	
	public void addOperation(Operation op) {
		this.getOperations().add(op);
	}
	
	public void addOperation(Operation op, int position) {
		this.getOperations().add(position, op);
	}
	
	public void removeOperation(Operation op) {
		this.getOperations().remove(op);
	}
	
	@SuppressWarnings("unchecked")
	public List<Object> call() throws Exception {
		List t = new ArrayList();
		
		for(Operation op: this.getOperations())
			t.add(op.call());
		
		return t;
	}

	public List<Operation> getOperations() {
		return operations;
	}

	public void setOperations(List<Operation> operations) {
		this.operations = operations;
	}
}